package org.budo.mybatis.criteria.query;

import java.util.HashSet;
import java.util.Set;

import org.budo.mybatis.criteria.query.parser.impl.TableJoinConfig;

/**
 * @author lmw
 */
public class ParsedCriteriaQuery extends CriteriaQuery {
    private static final long serialVersionUID = 62821782340366789L;

    private Set<TableJoinConfig> tableJoinConfigs = new HashSet<TableJoinConfig>();

    private StringBuffer whereSql = new StringBuffer();

    private StringBuffer selectSql = new StringBuffer();

    private StringBuffer joinSql = new StringBuffer();

    public ParsedCriteriaQuery() {}

    public ParsedCriteriaQuery(CriteriaQuery criteriaQuery) {
        this.setEntityType(criteriaQuery.getEntityType());
        this.setFields(criteriaQuery.getFields());
        this.setFilter(criteriaQuery.getFilter());
    }

    public StringBuffer getJoinSql() {
        return joinSql;
    }

    public StringBuffer getSelectSql() {
        return selectSql;
    }

    public void setJoinSql(StringBuffer joinSql) {
        this.joinSql = joinSql;
    }

    public void setSelectSql(StringBuffer selectSql) {
        this.selectSql = selectSql;
    }

    public StringBuffer getWhereSql() {
        return whereSql;
    }

    public void setWhereSql(StringBuffer whereSql) {
        this.whereSql = whereSql;
    }

    public Set<TableJoinConfig> getTableJoinConfigs() {
        return tableJoinConfigs;
    }

    public void setTableJoinConfigs(Set<TableJoinConfig> tableJoinConfigs) {
        this.tableJoinConfigs = tableJoinConfigs;
    }

    public String getSql() {
        return this.getSelectSql().toString() + " " + this.getJoinSql().toString() + " WHERE " + this.getWhereSql().toString();
    }

    public void addTableJoinConfig(TableJoinConfig tableJoinConfig) {
        this.getTableJoinConfigs().add(tableJoinConfig);
    }
}